<?php
class Herramientas_CalculadoraController extends Model3_Controller
{
    private $_credentials;
    
    public function init()
    {
        if(!Model3_Auth::isAuth())
            $this->redirect();
        else
        {
            $role = Model3_Auth::getCredentials('type');
            if( $role !== DefaultDb_Entity_User::TYPE_SENDER && $role !== DefaultDb_Entity_User::TYPE_TRANSPORTER )
            {
               Model3_Auth::deleteCredentials();
               $this->redirect();
            }
        }
        
        switch ($role)
        {
            case DefaultDb_Entity_User::TYPE_SENDER:
                $this->view->setTemplate('Customer');
                break;
                
                case DefaultDb_Entity_User::TYPE_TRANSPORTER:
                $this->view->setTemplate('Transporter');
                break;
        }
        $this->_credentials = Model3_Auth::getCredentials();
    }
    
    var $name = 'Links';
    var $helpers = array('Html', 'Form', 'Javascript');
    var $components = array('RequestHandler');
     
    function add() {
        if (!empty($this->data)) {
            if ($this->Link->save($this->data)) {
                //$this->flash('Enlace añadido.','/links',3);
            }
        }
        $this->set('links', $this->Link->findAll());
        //$this->render('index', 'ajax');
        $this->render('list');
    }
     
    function index() {
        
    }
}